package com.ep.modules.app.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ep.common.utils.PageUtils;
import com.ep.modules.app.dao.AppTransportPlansMapper;
import com.ep.modules.app.entity.AppTransportPlans;
import com.ep.modules.app.entity.AppTransportPlansExample;
import com.ep.modules.app.entity.AppTransportPlansWithBLOBs;
import com.ep.modules.app.service.AppTransportPlansService;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppTransportPlansServiceImpl implements AppTransportPlansService {
    @Autowired
    private AppTransportPlansMapper appTransportPlansMapper;

    public PageUtils queryPage(Map<String, Object> params) {
        String searchKey = (String)params.get("searchKey");
        Long searchUserId = (Long)params.get("searchUserId");
        AppTransportPlansExample example = new AppTransportPlansExample();
        AppTransportPlansExample.Criteria criteria = example.createCriteria();

        List<AppTransportPlansWithBLOBs> list = appTransportPlansMapper.selectByExampleWithBLOBs(example);
        Page<AppTransportPlansWithBLOBs> page = new Page<>();
        page.setRecords(list);
        return new PageUtils(page);
    }

    public AppTransportPlans getById(Long id) {
        return appTransportPlansMapper.selectByPrimaryKey(id.intValue());
    }

    public void save(AppTransportPlans entity) {
        // 创建 AppTransportPlansWithBLOBs 对象
        AppTransportPlansWithBLOBs entityWithBLOBs = new AppTransportPlansWithBLOBs();

        // 手动复制字段值
        entityWithBLOBs.setPlanId(entity.getPlanId());
        entityWithBLOBs.setOrderId(entity.getOrderId());
        entityWithBLOBs.setVehicleId(entity.getVehicleId());
        entityWithBLOBs.setDriverId(entity.getDriverId());
        entityWithBLOBs.setEstimatedDepartureTime(entity.getEstimatedDepartureTime());
        entityWithBLOBs.setEstimatedArrivalTime(entity.getEstimatedArrivalTime());

        appTransportPlansMapper.insert(entityWithBLOBs);
    }

    public void update(AppTransportPlans entity) {
        // 创建 AppTransportPlansWithBLOBs 对象
        AppTransportPlansWithBLOBs entityWithBLOBs = new AppTransportPlansWithBLOBs();

        // 手动复制字段值
        entityWithBLOBs.setPlanId(entity.getPlanId());
        entityWithBLOBs.setOrderId(entity.getOrderId());
        entityWithBLOBs.setVehicleId(entity.getVehicleId());
        entityWithBLOBs.setDriverId(entity.getDriverId());
        entityWithBLOBs.setEstimatedDepartureTime(entity.getEstimatedDepartureTime());
        entityWithBLOBs.setEstimatedArrivalTime(entity.getEstimatedArrivalTime());

        appTransportPlansMapper.updateByPrimaryKeySelective(entityWithBLOBs);
    }

    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
                appTransportPlansMapper.deleteByPrimaryKey(id.intValue());
        }
    }
}